﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WXYW.BLL;
using WXYW.DAL;

namespace WXYW
{
    public partial class ConfirmProductActively : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindApplication();
            }
        }

        private void BindApplication()
        {
            ApplicationService service = new ApplicationService();
            ApplicationForm form = service.GetApplicationFormByID(long.Parse(Request.QueryString[Constants.QUERYSTR_APPLICATION_ID]));
            if (!form.UserReference.IsLoaded)
            {
                form.UserReference.Load();
            }
            rmacodeLabel.Text = form.ApplicationCode;
            connectPersonLabel.Text = form.User.ContactPerson;
            phoneLabel.Text = form.User.UserPhone;
            userNameLabel.Text = form.User.FullName;
            sendbackLabel.Text = form.SendBackDateTime.HasValue ? Convert.ToDateTime(form.SendBackDateTime).ToString("yyyy-MM-dd") : "";
            receiveTimeTextBox.Text = DateTime.Now.ToString("yyyy-MM-dd");
        }

        protected void submitLinkButton_Click(object sender, EventArgs e)
        {
            ApplicationService service = new ApplicationService();
            ApplicationForm form = service.GetApplicationFormByID(long.Parse(Request.QueryString[Constants.QUERYSTR_APPLICATION_ID]));
            ConfirmReceiveProduct confirmRecord = new ConfirmReceiveProduct
            {
                Comment = commentTextBox.Text,
                ConfirmReceiveDateTime = DateTime.Now,
                ConfirmWay = wayRadioButtonList.SelectedValue,
                IsReceiveProduct = noRadioButton.Checked?true:false
            };
            form.ConfirmReceiveProduct.Add(confirmRecord);
            form.ClientReceiveDateTime = Convert.ToDateTime(receiveTimeTextBox.Text);
            form.Status = "客户信息反馈";
            service.UpdateApplication(form);
            Response.Write(string.Format("<script language='JavaScript'> alert( '信息已成功保存！');location.href= 'ListApplicationFormNeedClientConfirm.aspx' </script> ")); 
        }
    }
}
